/*
 * ******************************************************************************
 *   Copyright (c) 2013-2014 Gabriele Mariotti.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *  *****************************************************************************
 */

package it.gmariotti.cardslib.demo.fragment.nativeview;

import it.gmariotti.cardslib.demo.ResourceTable;
import it.gmariotti.cardslib.demo.cards.GoogleNowNativeWeatherCard;
import it.gmariotti.cardslib.demo.cards.GoogleNowStockCardwithList;
import it.gmariotti.cardslib.demo.fragment.BaseMaterialFragment;
import it.gmariotti.cardslib.library.view.CardView;
import ohos.aafwk.content.Intent;

/**
 * Card Examples
 *
 * @author Gabriele Mariotti (gabri.mariotti@gmail.com)
 */
public class NativeCardWithListFragment extends BaseMaterialFragment {

    GoogleNowNativeWeatherCard card;
    GoogleNowStockCardwithList card2;

    @Override
    protected int getSubTitleHeaderResourceId() {
        return ResourceTable.String_header_title_subtitle_cardwithlist;
    }

    @Override
    protected int getTitleHeaderResourceId() {
        return ResourceTable.String_header_title_group5;
    }

    @Override
    protected String getDocUrl() {
        return "";
    }

    @Override
    protected String getSourceUrl() {
        return "";
    }

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_demo_fragment_native_cardwithlist_card);
        initCard();
    }


    /**
     * This method builds a simple card
     */
    private void initCard() {

        //Create a Card
        card = new GoogleNowNativeWeatherCard(this);
        card.init();

        //Set card in the cardView
        CardView cardView = (CardView) this.findComponentById(ResourceTable.Id_carddemo_weathercard);
        cardView.setCard(card);


        //Card
        card2 = new GoogleNowStockCardwithList(this);
        card2.init();

        //Set card in the cardView
        CardView cardView2 = (CardView) this.findComponentById(ResourceTable.Id_carddemo_stockcard);
        cardView2.setCard(card2);

    }

    @Override
    protected void onBackground() {
        super.onBackground();
        if (card != null)
            card.unregisterDataSetObserver();
        if (card2 != null)
            card2.unregisterDataSetObserver();
    }
}
